package com.situ.car.controller;

import com.situ.car.pojo.entity.Permission;
import com.situ.car.service.IPermissionService;
import com.situ.car.service.Impl.PermissionServiceImpl;
import com.situ.car.util.Result;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/permission")
public class PermissionController extends BaseController{
    private IPermissionService permissionService = new PermissionServiceImpl();
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("PermissionController.service");
        String method = req.getParameter("method");
        switch (method) {
            case "selectAll":
                selectAll(req, resp);
                break;
        }
    }

    private void selectAll(HttpServletRequest req, HttpServletResponse resp) {
        System.out.println("PermissionController.selectAll");
        String roleId = req.getParameter("roleId");
        List<Permission> list = permissionService.selectAll(Integer.parseInt(roleId));
        toJSON(resp, Result.ok(list));
    }
}
